package com.example.hydropowermanage.service.lmpl;

import com.example.hydropowermanage.controller.MessageController;
import com.example.hydropowermanage.pojo.Message;
import com.example.hydropowermanage.mapper.MessageMapper;
import com.example.hydropowermanage.service.MessageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
@Service
public class MessageServiceImpl implements MessageService {
    private static final Logger logger = LoggerFactory.getLogger(MessageController.class);


    @Autowired
    MessageMapper messageMapper ;
    @Override
    public void sendNotification(String sender, String receiver, String content) {
        Message message = new Message();
        message.setSender(sender);
        message.setReceiver(receiver);
        message.setMsgContent(content);
        // 设置时间
        message.setSendTime(new Date());
        // 设置状态
        message.setRead("UNREAD");

        messageMapper.insertMessage(message);
    }

    @Override
    public List<Message> getUserMessages(String userId) {
        return messageMapper.getUserMessages(userId);
    }

    @Override
    public void markMessageAsRead(Long messageId) {
        messageMapper.updateMessageStatus(messageId, "READ");
    }
    @Override
    public void deleteMessage(Long messageId) {
        messageMapper.deleteMessage(messageId);
    }

}
